package com.greenhouse9.prog01.split;

public class Prog3 {

	private String filename;
	private String suffix;
	private int count = 0;
	private String hexCount;

	public Prog3(){};
	public Prog3(String vfilename){
		filename = vfilename;
	}

	public String nextFilename(){

		//hexCount = Integer.toHexString(count);
		hexCount = toRadixString(count);
		StringBuilder sb = new StringBuilder();
		while(sb.length() < 2){
			if(sb.length()+ hexCount.length() == 2){
				sb.append(hexCount);
			}
			else {
				//sb.append("0");
				sb.append("a");
			}
		}
		count++;
		return filename + sb.toString();
	}

	private String toRadixString(int num){

		if(num<0)return "-" + toRadixString(-num);

		String str = "abcdefghijklmnopqrstuvwxyz";
		int radix = str.length();

		StringBuilder sb = new StringBuilder();

		int quot=1;
		int remind;

		while (quot > 0){
			quot = num / radix;
			remind = num % radix;

			sb = sb.append(str.substring(remind, remind+1));
		}

		return sb.reverse().toString();
	}
}
